#导入本章示例用到的包
import numpy as np
import cv2 as cv
import matplotlib. pyplot as plt
from skimage import io, exposure, color, util

#改变图像亮度
img = cv.imread('./img/2.jpg', 0) #读入一幅灰度图像
#采用OpenCV函数
imgbu1= cv.add(img,100)
imgbd1= cv.subtract(img,75)
#采用NumPy数组运算
imgbu2= img.astype(np.float64)+100
imgbu2= np.clip(imgbu2,0,255).astype(np.uint8)
imgbd2= img.astype(np.float64)-75
imgbd2 = np.clip(imgbd2,0,255).astype(np.uint8)
cv.imshow('mask',imgbd1)
cv.imshow('2',imgbd2)
cv.waitKey(0)
